package com.mxpio.erp.common.workshop.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.model.Notice;
import com.mxpio.erp.common.jpa.model.NoticeLine;
import com.mxpio.erp.common.vo.OrderExcuteLineVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_WORKSHOP_OOPICKING_NOTICE")
@Schema(description="委外领料通知单")
public class OoPickingNotice extends Notice {

	private static final long serialVersionUID = 1L;

	@Column(name = "START_DATE_")
	@Schema(description = "计划开始日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date startDate;

	@Column(name = "END_DATE")
	@Schema(description = "计划完成日期")
	@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date endDate;

	@Schema(description = "加工商编号")
	@Column(name = "PN_CODE_")
	//@Dict(dicCode = "pnCode", dicEntity = Supply.class, dicText = "pnName")
	private String pnCode;

	@Schema(description = "加工商名称")
	@Column(name = "PN_NAME_")
	private String pnName;

	@Column(name = "PRODUCT_ITEM_CODE_")
	@Schema(description = "产品编号")
	private String productItemCode;

	@Column(name = "PRODUCT_ITEM_NAME_")
	@Schema(description = "产品名称")
	private String productItemName;
	@Column(name = "PRODUCT_DRAWING_NO_")
	@Schema(description = "图号")
	private String productDrawingNo;

	@Transient
	private List<OoPickingNoticeLine> ooPickingNoticeLines;

	@Transient
	private OutsourceOrder order;
	@Override
	public String initTypeCode() {
		return "NP1";
	}

	@Override
	public NoticeLine createLine(OrderExcuteLineVo orderExcuteVo) {
		OoPickingNoticeLine noticeLine = new OoPickingNoticeLine();
		noticeLine.setOriginBizLineNo(orderExcuteVo.getBizOrderlineNo());
		noticeLine.setOriginBizNo(orderExcuteVo.getBizOrderNo());
		noticeLine.setItemCode(orderExcuteVo.getItemCode());
		noticeLine.setNoticeNo(this.getNoticeNo());
		noticeLine.setQuantity(orderExcuteVo.getQuantity());
		noticeLine.setSort(orderExcuteVo.getSort());
		noticeLine.setLotNo(orderExcuteVo.getLotNo());
		noticeLine.setSubLotIndex(orderExcuteVo.getSubLotIndex());
		noticeLine.setSupplementReason(orderExcuteVo.getSupplementReason());//处理补料原因字段
		return noticeLine;
	}

	@Override
	public List<? extends NoticeLine> getNoticeLines() {
		return this.ooPickingNoticeLines;
	}

}
